package com.styytech.dadabao.utils;

import android.app.Activity;
import android.widget.BaseAdapter;

import com.styytech.dadabao.adapter.MyMessageItemAdapter;
import com.styytech.dadabao.adapter.NoticeItemAdapter;
import com.styytech.dadabao.adapter.ProductItemAdapter;
import com.styytech.dadabao.adapter.SaleRecordItemAdapter;
import com.styytech.dadabao.bean.MyMessage;
import com.styytech.dadabao.bean.Notice;
import com.styytech.dadabao.bean.RecommendProduct;
import com.styytech.dadabao.bean.SaleRecord;
import com.styytech.dadabao.bean.TransactionDetails;
import com.styytech.dadabao.bean.UserRecord;

import java.util.LinkedList;

public class AdapterUtils {

    /**
     * 获取相应的迭代器
     *
     * @param context
     * @param showList    加载的列表数据
     * @param adapterType 适配器类型
     * @return
     */
    public static BaseAdapter getAdapter(Activity context,
                                         LinkedList<Object> showList, int adapterType) {
        BaseAdapter adapter = null;

        if (showList == null) {
            return adapter;
        }
        if (showList.size() <= 0) {
            return adapter;
        }
        Object obj = showList.get(0);

        if (obj instanceof RecommendProduct) {
            adapter = new ProductItemAdapter(showList, context);
        } else if (obj instanceof SaleRecord) {
            adapter = new SaleRecordItemAdapter(showList, context);
        } else if (obj instanceof UserRecord) {
            adapter = new SaleRecordItemAdapter(showList, context);
        } else if (obj instanceof Notice) {
            adapter = new NoticeItemAdapter(showList, context);
        } else if (obj instanceof MyMessage) {
            adapter = new MyMessageItemAdapter(showList, context);
        }else if (obj instanceof TransactionDetails) {
            adapter = new SaleRecordItemAdapter(showList, context);
        }
        return adapter;
    }

}
